<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="Logic.Authorizer"%>
	<%@ page import="java.sql.*" %>
	<%@ page import="java.io.*" %> 
	<%@page import="servlet.FormsDropDown,Database.DBConnection"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	if (session.getAttribute("name") == null) {
		response.sendRedirect("login.jsp");
	} else {
		if (!Authorizer.checkRole("2", session.getAttribute("role")
				.toString())) {
			response.sendRedirect("nopermission.jsp");
		}
	}
%>
<jsp:include page="t_header.jsp" />

<!--  <div class="breadcrumbs_container">
	<article class="breadcrumbs"> <a href="Proc_NewProcess.jsp">Manage Processes</a>
	<div class="breadcrumb_divider"></div>
	<a class="current">Delete Form</a> 
	</article>
</div> -->
<jsp:include page="header.html" />

<!-- Declare sidebar -->
<jsp:include page="t_sidebarProcess.jsp" />

<!-- Main Content -->
<body>
	<section id="main" class="column">
		
	<article class="module width_3_quarter">
<form id="DeleteForm" name="DeleteForm" onsubmit="CFMDelete();">

<header><h3>Select a form to delete</h3></header>
<div class="module_content">
<fieldset><label>Form Name</label> : <select name="Fid" id="Fid" style="width: 80%">
						<%
							FormsDropDown FDD = new FormsDropDown(out);
							FDD.doGet(request, response);
							
						%>
					</select><br></fieldset>
					</div>
					<footer>
					<div class="submit_link">
					<input id="Delete" name="Delete" type="submit" value="Delete" class="alt_btn">
					</div>
					</footer>
					<input id="answer" name="answer" type="hidden"/>
				
					<%
	String answer = request.getParameter("answer");
  	 if(answer == null || "".equals(answer))answer = "false";
  	 	if("true".equals(answer)){
  	 		
	 System.out.println("User confirmed to delete.");
  	 String VarSelected=request.getParameter("Fid");
 
  			Connection con=null,con1=null; 
  			PreparedStatement stmt=null,stmt1=null; 
  			PreparedStatement ps=null,ps1=null; 
  			ResultSet rs=null,rs1=null; 
  			String sql="",sql1="",a=""; 
  			
  			con=DBConnection.connect(true); 
  			int j1=0; 
  			try
  			{ 
  				sql="DELETE FROM qmsdb.forms WHERE idForms='"+VarSelected+"'"; 
  				stmt = con.prepareStatement(sql);
  				j1=stmt.executeUpdate();
  				if(j1!=0) 
  	  			{ 				
  					System.out.println("Operation Completed Successfully! ");
  					  					  					%>
  					  					<script>
  					window.location="Proc_Process.jsp";
  					  					</script>
  					<%	
  	  			}
  		    }
  			catch(Exception ex) 
  			{ 
  				ex.printStackTrace(); 
  			} 
			finally{
	
			}
 }
 else
 {
 
 }
 %>
</form>
</article>
    
<script type="text/javascript">

function CFMDelete(){
	var TempVal=document.getElementById('Fid');
	var selectedText = TempVal.options[TempVal.selectedIndex].text;
	var answer = confirm ("Are you sure you want to continue deleting \n("+selectedText+")? ");
	  if (answer){
	              document.DeleteForm.answer.value = "true";  
	              document.DeleteForm.submit();
	            
	              return true;
	    }else 
	    alert("Please choose carefully before deleting! ");
	    return false;
	}

</script>
<div class="spacer"></div>
</section>
	<!-- Declare closing tags -->
	<jsp:include page="t_footer.jsp" />



